<%@page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
    <title>栏目管理</title>
	<%@ include file="/common/header/meta.jsp"%>
	<%@ include file="/common/header/script.jsp"%>
    <script type="text/javascript">
    var $tg, oldSort, pid ;
	$(function() {
		$tg = $("#tg").treegrid({
			url: $.webapp.root + "/admin/site/column/doNotNeedAuth_tree.do",
			idField: "id", treeField: "colName", rownumbers: true, cascadeCheck: true, border: false,
			toolbar: "#toolbars", striped: true, fit: true, remoteSort: false, singleSelect: true,
			frozenColumns: [[
				{ field: "ck", checkbox: true },
				{ field: "id", title: "ID", hidden: true }
			]],
			columns: [[
	            { field: "colName", title: "名称", width: 220, sortable: true },
	    		{ field: "sort", title: "排序", width: 50, sortable: true, editor: "numberbox" },
			    { field: "colUrl", title: "链接地址", width: 300, tooltip: true },
			    { field: 'isShow', title: '是否显示', width: 60, sortable: true, align: 'center', formatter:function(value,row){
			    	var str1 = $.string.format("<a href='javascript:push(\"{0}\")'><font color='red'>隐藏</font></a>", row.id);
			    	var str2 = $.string.format("<a href='javascript:push(\"{0}\")'><font color='#00CC00'>显示</font></a>", row.id);
			    	
			    	if(value == 0){return str1;}
			    	else if(value == 1){return str2;}
			    }},
			    { field: "created", title: "创建时间", width: 140, sortable: true }
			]],
            autoEditing: true, extEditing: true, singleEditing: true,
            onBeforeEdit: function(data) {
        		$.fn.treegrid.extensions.onBeforeEdit.apply(this, arguments);
	        	pid = data.pid ; oldSort = data.sort ;
	        },
	        onAfterEdit: function(data) {
	            $.fn.treegrid.extensions.onAfterEdit.apply(this, arguments);
	            if(oldSort != data.sort) {
	            	var o = {oldSort: oldSort, newSort: data.sort, id: data.id, pid: (undefined == data.pid?"":data.pid)};
	            	$.post($.webapp.root + "/admin/site/column/doNotNeedAuth_sort.do", o, function(result) {
	            		$tg.treegrid("reload") ; $.easyui.loaded();
	        		}).error(function() { $.easyui.loaded(); });
	            }
	        },
	        onLoadSuccess: function() {
            	$.fn.treegrid.extensions.onLoadSuccess.apply(this, arguments);
	         }
		});
	});
	
	function push(id) {
    	$.post($.webapp.root+"/admin/site/column/doNotNeedAuth_push.do", {"id" : id}, function(result) {
    		if (result.status) {
    			$tg.treegrid('unselectAll');$tg.treegrid('reload') ;
				alertify.success(result.msg);
				$.easyui.loaded();
			} else {
				alertify.warning(result.msg);
				$.easyui.loaded();
			}
		}, 'json').error(function() { $.easyui.loaded(); });
    }
	
	function form_edit(form) {
		var form_url = $.webapp.root + "/admin/site/column/col_form_UI.do" ;
		if("E" == form) {
			var node = $tg.treegrid("getSelected");
			if (node) {
				form_url = $.webapp.root + "/admin/site/column/col_form_UI.do?id="+node.id ;
			} else {
				alertify.warning("请选择一条记录！"); return ;
			}
		}
		var $d = $.easyui.showDialog({
			href: form_url, title: "表单", iniframe: false, topMost: true, width: 740 , height: 400,
	        enableApplyButton: false, enableCloseButton: false,  enableSaveButton: false,
	        buttons : [ 
			  { text : "保存并继续", iconCls : "icon-standard-disk", handler : function() { $.easyui.parent.submitForm($d, $tg, true) ; } },
	          { text : "确定", iconCls : "ext_save", handler : function() { $.easyui.parent.submitForm($d, $tg) ; } },
	          { text : "关闭", iconCls : "ext_cancel", handler : function() { $d.dialog("destroy"); } }
	       	]
	    });
	}
	
	function del() {
		var node = $tg.treegrid("getSelected");
		if(node){
			$.messager.confirm("您确定要进行该操作？", function (c) { 
				if(c) {
					$.easyui.loading({ msg: "数据删除中，请稍等..." });
					$.post($.webapp.root + "/admin/site/column/delete.do", {id:node.id}, function(result) {
						if (result.status) {
							$tg.treegrid("reload") ; $.easyui.loaded();
							alertify.success(result.msg);
						} else {
							$.easyui.loaded();alertify.error(result.msg);
						}
					}, "json").error(function(){$.easyui.loaded();});
				} 
			});
		} else {
			alertify.warning("请选择一条记录！");
		}
	}
    </script>
</head>

<body>

	<div id="tg">
		<div id="toolbars">
            <a onClick="form_edit('A');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_add'">添加</a>
            <a onClick="form_edit('E');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_edit'">编辑</a>
            <a onClick="del();" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_remove'">删除</a>
            <a onclick="$tg.treegrid('reload');" class="easyui-linkbutton" data-options="plain: true, iconCls: 'ext_reload'">刷新</a>
        </div>
	</div>
    
</body>
</html>



